package com.deeper.customview.ui.c5.demo.c05d03;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter05Demo03Fragment extends BaseFragment {
    private CodeView codeView;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter05_demo03, container, false);
        codeView = root.findViewById(R.id.codeView);
        initListener(root);

        return root;
    }


    public void initListener(View root) {
        root.findViewById(R.id.refresh).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                codeView.refresh();
            }
        });
        root.findViewById(R.id.changeColor).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                codeView.setColor(Color.BLUE);
            }
        });
        root.findViewById(R.id.changeFont).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                codeView.setFontSize(100);
            }
        });
        root.findViewById(R.id.textCount).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                codeView.setCount(5);
            }
        });
        root.findViewById(R.id.lineCount).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                codeView.setLineCount(150);
            }
        });
        root.findViewById(R.id.get).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String code = codeView.theCode();
                Toast.makeText(getActivity(), code, Toast.LENGTH_SHORT).show();
            }
        });
    }
}
